import { datafluxRum } from '@cloudcare/browser-rum';

export default function ({ $config }, inject) {
  // Nuxt2 中插件无法直接访问环境变量，需在 nuxt.config.js 中暴露变量，然后通过 $config 引用
  const { cloudcare } = $config;
  
  datafluxRum.init({
    applicationId: cloudcare.applicationId,
    site: cloudcare.site,
    clientToken: cloudcare.clientToken,
    env: cloudcare.env,
    version: cloudcare.version,
    service: cloudcare.service,
    sessionSampleRate: 100,
    sessionReplaySampleRate: 100,
    compressIntakeRequests: true,
    trackInteractions: true,
    traceType: 'ddtrace',
    allowedTracingOrigins: [/.*/],
  });
  datafluxRum.startSessionReplayRecording();
  
  // 将 SDK 注入到 Vue 实例中，以便在组件中使用
  inject('rum', datafluxRum);
}
